﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DataAccess;
using System.IO;
using System.Collections;

namespace CarService
{
    public partial class Gallery : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Load_Data();
            Load_Gallery();
            if (!Page.IsPostBack)
            {
            }
        }

        private void Load_Data()
        {
            SettingInfo settingInfo = SettingData.SelectBySiteID(Config.Global.Settings.SiteID);
            Page.Title = "Hình ảnh - " + settingInfo.SiteName + " - " + settingInfo.SiteURL;
            Page.MetaDescription = settingInfo.SiteDescription;
            Page.MetaKeywords = settingInfo.SiteKeyword;
        }

        private void Load_Gallery()
        {
            ArrayList arrImages = new ArrayList();
            int i = 0;
            string webRoot = Config.Global.Settings.WebRoot;
            foreach (string fileName in Directory.GetFiles(Server.MapPath(@"~/" + Config.Global.Settings.GalleryPath)))
            {
                int pos = fileName.LastIndexOf('\\');
                string imageName = webRoot + "/" + Config.Global.Settings.GalleryPath + fileName.Substring(pos+1);
                arrImages.Add(new Evaluation(i, imageName));
                i++;
            }

            if (arrImages != null)
            {
                rptImage.DataSource = arrImages;
                rptImage.DataBind();
            }
        }

        public class Evaluation
        {

            private int imageID;
            private string imageName;

            public Evaluation(int imageID, string imageName)
            {
                this.imageID = imageID;
                this.imageName = imageName;
            }

            public int ImageID
            {
                get
                {
                    return imageID;
                }
            }

            public string ImageName
            {
                get
                {
                    return imageName;
                }
            }
        }
    }
}